Take a ZIP file) of images and process them, using a library built into python that you need to learn how to use. A ZIP file takes several different files and compresses them, thus saving space, into one single file. The files in the ZIP file we provide are newspaper images (like you saw in week 3). Your task is to write python code which allows one to search through the images looking for the occurrences of keywords and faces. E.g. if you search for "pizza" it will return a contact sheet of all of the faces which were located on the newspaper page which mentions "pizza". This will test your ability to learn a new (library), your ability to use OpenCV to detect faces, your ability to use tesseract to do optical character recognition, and your ability to use PIL to composite images together into contact sheets.
Each page of the newspapers is saved as a single PNG image in a file called images.zip. These newspapers are in english, and contain a variety of stories, advertisements and images. Note: This file is fairly large (~200 MB) and may take some time to work with, I would encourage you to use small_img.zip for testing.
Here's an example of the output expected. Using the small_img.zip file, if I search for the string "Christopher" I should see the following image:
If I were to use the images.zip file and search for "Mark" I should see the following image (note that there are times when there are no faces on a page, but a word is found!):

Note: That big file can take some time to process - for me it took nearly ten minutes! Use the small one for testing.
import zipfile
from PIL import Image, ImageDraw, ImageFont
import pytesseract
import cv2 as cv
import numpy as np
# loading the face detection classifier
face_cascade = cv.CascadeClassifier('readonly/haarcascade_frontalface_default.xml')
# Font or text displaying the filename
font = ImageFont.truetype("readonly/fanwood-webfont.ttf", size=16)
# Total Number of extracted files
# Also Iterator Variable for database for loops
img_files_nr = 0
# Database: 5 Lists
# List which contains list of all filenames
img_filen_m_lst = []
# List which contains list of the discovered texts with text recognition
text_disc_m_lst = []
# List which contains information if the searched text is found
txt_found_bool_m_lst = []
# List which contains list of all facial bounding boxes
f_boxes_m_lst = []
# Extract Zip Files
try:
with zipfile.ZipFile("readonly/images.zip", mode="r") as images_zipfile:
img_filen_m_lst = images_zipfile.namelist()
images_zipfile.extractall()
except zipfile.BadZipfile as error:
print(error)
# Open to check extraction worked
first_image = Image.open(img_filen_m_lst[0])
display(first_image)
img_files_nr = len(img_filen_m_lst)
print("printing img_filen_m_lst: ")
print(img_filen_m_lst)
print(img_files_nr)
print("printing f_boxes_m_lst: ")
print(f_boxes_m_lst)